// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: 'sungodd00-bf5531'
})

const db = cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {
  const {
    OPENID
  } = cloud.getWXContext();
  console.log(event,"this is event");
  try {
    const result = await cloud.openapi.subscribeMessage.send({
      touser: OPENID,
      page: `/page/blog-comment/blog-comment?blogId=${event.blogId}`,
      data: {
        thing1: {
          value: event.content
        },
        time2: {
          value: event.createTime
        },
        name3: {
          value: event.nickName || ''
        }
      },
      templateId: 'ESy95hWPUXPfoveViyiekUIMfbsXeZMNcSTcvij_YLM'
    })
    return result;
  } catch (err) {
    // 错误处理
    // err.errCode !== 0
    throw err
  }
}